package controller.teacher;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import pojos.subject.ClassInfoManager;
import service.TeacherInfoService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 教师页面控制器
 */
@Controller
@RequestMapping(value = {"/teacher"})
public class TeacherPageController {

    @Resource(name="teacherInfoService")
    private TeacherInfoService teacherInfoService;

    /**
     * 教师控制台界面
     */
    @GetMapping("/console")
    public ModelAndView teacherConsolePage(HttpServletRequest request){
        HttpSession session = request.getSession();

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("TeacherInfo",session.getAttribute("UserInfo"));
        modelAndView.setViewName("/jsp/teacher/Console.jsp");

        return modelAndView;
    }

    /**
     * 教师控制台主页
     */
    @GetMapping("/frame/index")
    public ModelAndView teacherConsoleIndexPage(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/jsp/teacher/Frame-Index.jsp");
        return modelAndView;
    }

    /**
     * 教师信息界面
     */
    @GetMapping("/frame/personalInfo")
    public ModelAndView teacherInfoPage(HttpServletRequest request){
        HttpSession session = request.getSession();

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("TeacherInfo",session.getAttribute("UserInfo"));
        modelAndView.setViewName("/jsp/teacher/Frame-PersonalInfo.jsp");

        return modelAndView;
    }

    /**
     * 教师修改基础信息界面
     */
    @GetMapping("/frame/alterBaseInfoPage")
    public ModelAndView teacherAlterBaseInfoPage(HttpServletRequest request){
        HttpSession session = request.getSession();

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("TeacherInfo",session.getAttribute("UserInfo"));
        modelAndView.setViewName("/jsp/teacher/Frame-ChangeBaseInfo.jsp");

        return modelAndView;
    }

    /**
     * 教师修改登录信息界面
     */
    @GetMapping("/frame/alterLoginInfoPage")
    public ModelAndView teacherAlterLoginInfoPage(HttpServletRequest request){
        HttpSession session = request.getSession();

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("TeacherInfo",session.getAttribute("UserInfo"));
        modelAndView.setViewName("/jsp/teacher/Frame-ChangeLoginInfo.jsp");

        return modelAndView;
    }

    /**
     * 教师修改联系信息界面
     */
    @GetMapping("/frame/alterConnectInfoPage")
    public ModelAndView teacherAlterConnectInfo(HttpServletRequest request){
        HttpSession session = request.getSession();

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("TeacherInfo",session.getAttribute("UserInfo"));
        modelAndView.setViewName("/jsp/teacher/Frame-ChangeConnectInfo.jsp");

        return modelAndView;
    }

    /**
     * 教师课程信息页面
     */
    @GetMapping("/frame/my-course")
    public String teacherClassInfo(){
        return "forward:/pages/teacher/Console-Frame-ClassInfo.html";
    }

    /**
     * 教师添加课程信息界面
     */
    @GetMapping("/frame/add-class")
    public String teacherAddClassPage(){
        return "forward:/pages/teacher/Console-Frame-AddClass.html";
    }

    /**
     * 教师修改课程信息界面
     */
    @GetMapping("/frame/query-class-info")
    public ModelAndView teacherAlterClassPage(Integer classId){
        ModelAndView modelAndView = new ModelAndView();

        if(classId != null){
            ClassInfoManager classInfoManager = teacherInfoService.queryClassInfo(classId);
            if(classInfoManager != null){
                modelAndView.addObject("ClassInfo",classInfoManager);
            }
        }

        modelAndView.setViewName("/jsp/teacher/Frame-AlterClassInfo.jsp");

        return modelAndView;
    }

    /**
     * 教师修改头像界面
     */
    @GetMapping("/frame/update-avatar")
    public String teacherAlterAvatarPage(){
        return "forward:/pages/teacher/Console-Frame-UpdateAvatar.html";
    }
}
